<template>
	<view>
		<image src="../../static/me/bg3.jpg" mode="" style="position: fixed;top: 0; left: 0;width: 100vw; height: 100vh;"></image>
		<view style="z-index: 100;position: absolute;width: 100vw;padding-top: 10vh;">
			<view style="padding: 0 30rpx;">
				<!-- 用户头像和用户昵称 -->
				<view class="d-flex flex-column bg-white user-box">
					<view class="d-flex align-items-center">
						<view class="avatar" @tap="toUserInfo">
							<image v-if="userInfo" :src="userInfo.wxAvatar"></image>
							<image v-else src="/static/tabBar/user.png"></image>
						</view>
						<view class="d-flex flex-column flex-fill overflow-hidden" style="margin-top: 20rpx;">
							<view v-if="userInfo" class="font-size-lg font-weight-bold d-flex justify-content-start align-items-center" >
								<view class="text-truncate">{{ userInfo.name }}</view>
								<view class="iconfont line-height-100"></view>
							</view>
							<view v-else class="font-size-lg font-weight-bold" @tap="toLogin">请先登录</view>
						</view>
					</view>
				</view>
				<!-- user box end -->
			</view>
			<!-- 我的服务 begin -->
			<view class="service-box">
				<view class="font-size-lg text-color-base font-weight-bold" style="margin-bottom: 20rpx;"></view>
				<view class="row">
					<!-- 送水员就显示送水记录 -->
					<view class="grid" @tap="toTaskHistory()" v-if="userInfo && userInfo.userType == '送水员'">
						<view class="image"><image src="/static/me/icon/rili.png"></image></view>
						<view>送水记录</view>
					</view>
					<!-- 学生就显示所在寝室 -->
					<view class="grid" @tap="toMyDormitory()" v-else="userInfo && userInfo.userType == '学生'">
						<view class="image"><image src="/static/me/icon/dengta.png"></image></view>
						<view>我的寝室</view>
					</view>
					<view class="grid" @tap="toTicket()" >
						<view class="image"><image src="/static/me/icon/youjian.png"></image></view>
						<view>桶装水票</view>
					</view>
					<view class="grid" @tap="toCallAdminUser()">
						<view class="image"><image src="/static/me/icon/shouji.png"></image></view>
						<view>联系客服</view>
					</view>
					<view class="grid" @tap="logout">
						<view class="image"><image src="/static/me/icon/lvhang.png"></image></view>
						<view>退出登录</view>
					</view>
				</view>
			</view>
			<!-- 学生的我的服务 box end -->

			<!-- 其他服务 box begin -->
			<view class="service-box" style="margin-top:15rpx" >
				<view class="font-size-lg text-color-base font-weight-bold" style="margin-bottom: 20rpx;"></view>
				<view class="row">
					<view class="grid" @tap="services" >
						<view class="image"><image src="/static/me/icon/zhuti.png"></image></view>
						<view>更多</view>
					</view>
				</view>
			</view>
			<!-- 其他服务 box end -->
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			userInfo: null,
			newIcon: 'https://img-shop.qmimg.cn/s16/images/2020/05/12/ffb0613dded704b6.png'
		};
	},
	onShow() {
		this.userInfo = uni.getStorageSync("userInfo")
	},
	methods: {
		toLogin() {
			uni.navigateTo({
				url: '/pages/login/login'
			});
		},
		// 退出登录
		logout() {
			let that = this;
			if (!that.userInfo) {
				that.$msg('请先登录');
				return;
			}
			uni.showModal({
				content: '是否退出登录?',
				cancelText: '取消',
				confirmText: '退出登录',
				success: function(e) {
					if (e.confirm) {
						that.userInfo = null;
						if (uni.getStorageSync("userType") == '学生') {
							that.$request('/student/logout', 'delete').then(result => {
								uni.removeStorageSync("userInfo");
								that.$msg("已退出登录")
							});
						} else {
							that.$request('/worker/logout', 'delete').then(result => {
								uni.removeStorageSync("userInfo");
								that.$msg("已退出登录")
							});
						}
					}
				}
			});
		},
		// 
		toTicket() {
			uni.navigateTo({
				url: '/pages/ticket/ticketIndex'
			});
		},
		// 去我的寝室
		toMyDormitory() {
			if (!this.userInfo) this.toLogin();
			else {
				uni.navigateTo({
					url: '/pages/me/dormitory/address'
				});
			}
		},
		// 去送水记录
		toTaskHistory() {
			if (!this.userInfo) this.toLogin();
			else {
				uni.navigateTo({
					url: '/pages/task/taskHistory'
				});
			}
		},
		// 去联系客服
		toCallAdminUser() {
			uni.navigateTo({
				url: '../services/callAdminUser/index'
			});
		},
		toUserInfo() {
			if (!this.userInfo) this.toLogin();
			else {
				uni.navigateTo({
					url: '/pages/me/userInfo'
				});
			}
		},
		services() {
			uni.navigateTo({
				url: '/pages/services/services'
			});
		}
	}
};
</script>

<style lang="scss" scoped>
page {
	height: auto;
	min-height: 100%;
}

.bg {
	width: 100%;
	height: calc(410 / 594 * 750rpx);
}

.hym-btn {
	position: absolute;
	top: 40rpx;
	right: 40rpx;
	color: $color-primary;
	display: flex;
	align-items: center;
	justify-content: center;
	border-radius: 50rem;
	font-size: $font-size-sm;
	box-shadow: 0 0 20rpx rgba(66, 66, 66, 0.1);
	&::after {
		border: 0;
	}

	image {
		width: 30rpx;
		height: 30rpx;
		margin-right: 10rpx;
	}
}

.user-box {
	position: relative;
	border-radius: 8rpx;
	margin-bottom: 30rpx;
	box-shadow: $box-shadow;
}

.avatar {
	position: relative;
	margin-top: -35rpx;
	margin-left: 35rpx;
	margin-right: 35rpx;
	width: 160rpx;
	height: 160rpx;
	border-radius: 100%;
	display: flex;
	align-items: center;
	justify-content: center;
	background-color: #ffffff;
	box-shadow: 0 0 20rpx rgba($color: #000000, $alpha: 0.2);

	image {
		width: 140rpx;
		height: 140rpx;
		border-radius: 100%;
	}

	.badge {
		position: absolute;
		right: -10rpx;
		bottom: -10rpx;
		background-color: #ffffff;
		border-radius: 50rem;
		display: flex;
		align-items: center;
		justify-content: center;
		color: $color-warning;
		font-size: 24rpx;
		padding: 8rpx 16rpx;
		box-shadow: 0 0 20rpx rgba($color: #000000, $alpha: 0.2);

		image {
			width: 30rpx;
			height: 30rpx;
		}
	}
}

.level-benefit {
	margin-left: 35rpx;
	padding: 10rpx 0 10rpx 30rpx;
	border-radius: 50rem 0 0 50rem;
}

.user-grid {
	width: 25%;
	padding: 30rpx;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;

	.value {
		margin-bottom: 20rpx;
	}
}

.level-benefit-box {
	border-radius: 8rpx;
	margin-bottom: 30rpx;
	box-shadow: 0 10rpx 8rpx rgba($color: #878889, $alpha: 0.1);
	width: 100%;
	display: flex;
	padding: 30rpx;
	flex-direction: column;
	background-color: #ffffff;

	.row {
		display: flex;
		padding: 30rpx 0 20rpx;
		justify-content: space-around;
		align-items: center;

		.grid {
			width: 20%;
			display: flex;
			flex-direction: column;
			font-size: $font-size-sm;
			color: $text-color-assist;
			align-items: center;

			image {
				width: 80rpx;
				height: 80rpx;
				margin-bottom: 10rpx;
			}
		}
	}
}

.banner {
	width: 100%;
	border-radius: 8rpx;
	margin-bottom: 30rpx;
}

.service-box {
	width: 100%;
	background-color: #ffffff;
	padding: 32rpx 30rpx 10rpx;
	box-shadow: $box-shadow;

	.row {
		display: flex;
		flex-wrap: wrap;
		color: $text-color-assist;
		font-size: $font-size-sm;
		padding-bottom: -40rpx;

		.grid {
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			margin-bottom: 40rpx;
			width: 25%;
			position: relative;

			.image {
				image {
					width: 80rpx;
					height: 80rpx;
					margin-bottom: 20rpx;
				}
			}

			.new-badage {
				width: 40rpx;
				height: 40rpx;
				position: absolute;
				top: 0;
				right: 30rpx;
			}
		}
	}
}
</style>
